//
//  ViewController.m
//  stagesetptcture
//
//  Created by bigarto-mac1 on 2018/1/30.
//  Copyright © 2018年 bigarto-mac1. All rights reserved.
//

#define kScreen_Height [UIScreen mainScreen].bounds.size.height
#define kScreen_Width [UIScreen mainScreen].bounds.size.width

#import "ViewController.h"
#import "NextViewController.h"

@interface ViewController ()

@property (nonatomic, strong) UIImageView *imageView1;

@property (nonatomic, strong) UIImageView *imageView2;

@property (nonatomic, strong) UIImageView *imageView3;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.view.backgroundColor = [UIColor cyanColor];
    
    if (!_imageView1) {
        _imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, kScreen_Width / 2, kScreen_Width / 2)];
        _imageView1.backgroundColor = [UIColor colorWithWhite:1.000 alpha:0.500];
        _imageView1.contentMode = UIViewContentModeScaleAspectFit;
        _imageView1.image = [UIImage imageNamed:@"height"];
        _imageView1.userInteractionEnabled = YES;
        [_imageView1 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotoSyntheticImage:)]];
        [self.view addSubview:_imageView1];
    }
    
    if (!_imageView2) {
        _imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(kScreen_Width / 2, 64, kScreen_Width / 2, kScreen_Width / 2)];
        _imageView2.backgroundColor = [UIColor colorWithWhite:1.000 alpha:0.500];
        _imageView2.contentMode = UIViewContentModeScaleAspectFit;
        _imageView2.image = [UIImage imageNamed:@"width.jpg"];
        _imageView2.userInteractionEnabled = YES;
        [_imageView2 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotoSyntheticImage:)]];
        [self.view addSubview:_imageView2];
    }
    
    if (!_imageView3) {
        CGFloat height = kScreen_Height - kScreen_Width / 2 - 64;
        if (height > kScreen_Width) {
            height = kScreen_Width;
        }
        _imageView3 = [[UIImageView alloc] initWithFrame:CGRectMake((kScreen_Width - height) / 2, 64 + kScreen_Width / 2, height, height)];
        _imageView3.backgroundColor = [UIColor colorWithWhite:1.000 alpha:0.500];
        _imageView3.contentMode = UIViewContentModeScaleAspectFit;
        [self.view addSubview:_imageView3];
    }
}

- (void)gotoSyntheticImage:(UITapGestureRecognizer *)gestureRecognizer {
    UIImageView *imageView = (UIImageView *)gestureRecognizer.view;
    NextViewController *vc = [[NextViewController alloc] init];
    vc.image = imageView.image;
    __weak typeof (self) weakSelf = self;
    vc.syntheticSuccessBlock = ^(UIImage *image) {
        weakSelf.imageView3.image = image;
    };
    [self.navigationController pushViewController:vc animated:YES];
}

@end
